<!--论文隐匿名评审结果-->
<template>
    <div class="con">
        <div>
            <ConditionCard shadow="never" body-style="padding: 24px 24px 6px 24px;" @search="onSubmit" @reset="reset('queryForm')">
                <el-form ref="queryForm" label-suffix="：" :model="queryForm" label-position="right" label-width="120px">
                    <el-row :gutter="24">
                        <el-col :span="8">
                            <el-form-item :label="$t('label.schoolTerm')">
                                <CalendarSelect v-model="queryForm.yearTerm" @load-done="loadDone" :all="true"></CalendarSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.grade')">
                                <el-date-picker v-model="queryForm.grade" value-format="yyyy" :clearable="true" type="year" :placeholder="$t('paperBlindTrial.gredeTips')" style="width: 100%" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.college')">
                              <el-select
                                v-model="queryForm.academyCode"
                                style="width: 100%;"
                                clearable
                                filterable
                                :placeholder="$t('common.text.all')"
                                v-clearreadonly
                              >
                                <el-option
                                    v-for="item in options.academyCode"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                              </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="8">
                            <el-form-item :label="$t('courseSummary.major')">
                                <MyMajor :faculty="queryForm.academyCode" :filterable="true" :grade="queryForm.grade" v-model="queryForm.majorCode" :clearable="true" v-clearreadonly> </MyMajor>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.trainingLevel')" prop="eduLevel">
                                <DictSelect v-model="queryForm.eduLevel" :data="options.eduLevel" :clearable="true" ></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.trainingCategory')" prop="eduMode">
                                <DictSelect v-model="queryForm.eduMode" :filterable="true" :data="options.eduMode" :clearable="true" ></DictSelect>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="8">
                            <el-form-item :label="$t('label.degreeCategory')" prop="degreeType">
                                <DictSelect v-model="queryForm.degreeType" :data="options.degreeType" :clearable="true"></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('label.formLearning')" prop="studyForm">
                                <DictSelect v-model="queryForm.studyForm" :data="options.studyForm" :clearable="true"></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('paperBlindTrial.sendCount')">
                              <DictSelect v-model="queryForm.evaCount" :data="options.passCount" :clearable="true"></DictSelect>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <el-col :span="8">
                            <el-form-item :label="$t('paperBlindTrial.assessResult')">
                                <DictSelect v-model="queryForm.finalResult" :data="options.resultType" :clearable="true"></DictSelect>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('paperBlindTrial.batchName')">
                              <el-input v-model="queryForm.batchNo" :placeholder="$t('common.pla.pleaseInput')"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                          <el-form-item :label="$t('achievementApply.thesisTitle')">
                            <el-input v-model="queryForm.thesisTitle" :placeholder="$t('common.pla.pleaseInput')" :clearable="true"></el-input>
                          </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="24">
                      <el-col :span="8">
                        <el-form-item :label="$t('paperBlindTrial.manageDept')">
                          <DictSelect v-model="queryForm.manageDeptId" :data="options.manageDeptIds" :clearable="true"></DictSelect>
                        </el-form-item>
                      </el-col>
                      <el-col :span="8">
                        <el-form-item :label="$t('paperBlindTrial.tutor')" v-if="!global.isAnyTeacher">
                          <el-select v-model="queryForm.stuTutorNo" :remote-method="selectTeacher"  :placeholder="$t('paperBlindTrial.teacherNameTips')"
                                     filterable remote style="width: 100%;" :clearable="true" v-clearreadonly>
                            <el-option v-for="item in teachers" :key="item.value" :label="item.label" :value="item.value"/>
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                </el-form>
            </ConditionCard>
            <el-card shadow="never" body-style="padding: 24px;">
              <h1 class="condition-title">{{$t('paperBlindTrial.reviewResultTitle')}}</h1>
              <div class="edu-opertion-bar">
                  <div class="float-left">
                      <KeywordInput v-model="queryForm.stuNoOrName" :placeholder="$t('achievementApply.tableIplaceholder')" @enter="search"></KeywordInput>
                  </div>
                  <div class="float-right">
                      <el-button type="primary" @click="exportData">{{$t('common.btn.export')}}</el-button>
                      <el-button v-if="global.isAdmin && authsBtnState.clearEnterResultState " type="primary" @click="clearEnterResult">{{$t('paperBlindTrial.clearEntry')}}</el-button>
                  </div>
              </div>
              <edu-table ref="tables" :url="tableApi"  @selection-change="handleSelectionChange" :orderFixed="true">
                  <el-table-column :min-width="item.width" v-for="item in label" :key="item.props" :label="item.label" :prop="item.props" :fixed="item.fixed" show-overflow-tooltip>
                    <template slot-scope="scope">
                      <span v-if="item.props == 'evaCount'">{{scope.row.evaCount==0?'':scope.row.evaCount}}</span>
                      <!-- <span v-else-if="item.props == 'needPassCount'">{{scope.row.needPassCount==0?'':scope.row.needPassCount}}</span> -->
                      <span v-else>{{scope.row[item.props]}}</span>
                    </template>
                  </el-table-column>
                  <el-table-column :min-width="100" :label="$t('paperBlindTrial.assessResult')" prop="finalResult" show-overflow-tooltip fixed="right"
                  :formatter="(row) => { return fieldChange(options.resultType, row.finalResult); }">
                  </el-table-column>
                  <!-- 导师不能录入成绩，只能查看  -->
                  <el-table-column width="130px" :label="$t('nonPublicCourseOpen.operation')" fixed="right">
                      <template slot-scope="scope">
                          <div class="con_btns">
                              <el-button type="text" v-if="scope.row.finalResult ==='INCOMPLETE'" @click="showDialog('input', scope.row)">{{$t('paperBlindTrial.inputLabel')}}</el-button>
                              <el-button type="text" @click="showDialog('view', scope.row)">{{$t('message.Look')}}</el-button>
                          </div>
                      </template>
                  </el-table-column>
              </edu-table>
            </el-card>
        </div>
        <!-- 录入/查看评审详情 -->
        <el-dialog :visible.sync="dialogFlag" :title="titles" width="800px">
          <reviewDetails v-if="dialogFlag&&enterFlag" :row="rows" ref="reviewDetails" :viewState="typeInfo=='view'" @emit:back="backFunc"></reviewDetails>
          <reviewDetails v-if="dialogFlag&&!enterFlag" type='apply' :row="rows" ref="reviewDetails" :viewState="typeInfo=='view'" @emit:back="backFunc"></reviewDetails>
          <span slot="footer" class="dialog-footer">
            <span v-if="typeInfo==='input'">
              <el-button @click="dialogFlag = false">{{$t('message.cancel')}}</el-button>
              <el-button type="primary" @click="sure">{{$t('message.confirm')}}</el-button>
            </span>
            <el-button v-else @click="dialogFlag = false">{{$t('common.btn.close')}}</el-button>
          </span>
        </el-dialog>
    </div>
</template>

<script>
import { resultTableList, resultTableExportTable, clearEnterResult } from "common/src/api/paperBlindTrial/paperBlindTrial";
import MyMajor from "common/src/views/administrator/undergraduateTutor/component/MyMajor";
import commonMixins from 'common/src/views/practiceManagement/commonMixins';
import reviewDetails from './reviewDetails';
import { findTeacherInfoList } from 'common/src/api/studentinfo';
import mixin from 'common/src/mixins/index';
export default {
    components: {
        MyMajor,
        reviewDetails
    },
    mixins: [commonMixins,mixin],
    props: {},
    data() {
        return {
            auths:[],
            teachers:[],// 导师信息
            authsBtnState: {
                clearEnterResultState: false
            },
            tableApi: resultTableList,
            rows: {},
            yearTerms: '',
            queryForm: {
              manageDeptId: '',
              yearTerm: '',
              grade: '',
              academyCode: '',
              majorCode: '',
              eduLevel: '',
              eduMode: '',
              degreeType: '',
              studyForm: '',
              evaCount: '',
              stuTutorNo: '',
              batchNo: '',
              finalResult: '',
              thesisTitle: '',
            },
            label: [
                { label: this.$t('label.schoolTerm'), props: 'yearTermI18n', width: 170 },
                { label: this.$t('label.stuCode'), props: 'stuNo', width: 90,fixed:'left' },
                { label: this.$t('label.stuName'), props: 'stuName', width: 70,fixed:'left' },
                { label: this.$t('paperBlindTrial.manageDept'), props: 'manageDeptIdI18n', width: 120 },
                { label: this.$t('label.grade'), props: 'grade', width: 80 },
                { label: this.$t('label.college'), props: 'academyName', width: 150 },
                { label: this.$t('courseSummary.major'), props: 'majorName', width: 150 },
                { label: this.$t('label.trainingLevel'), props: 'eduLevelI18n', width: 80 },
                { label: this.$t('label.trainingCategory'), props: 'eduModeI18n', width: 100 },
                { label: this.$t('label.degreeCategory'), props: 'degreeTypeI18n', width: 80 },
                { label: this.$t('label.formLearning'), props: 'studyFormI18n', width: 80 },
                { label: this.$t('paperBlindTrial.stuTutorNo'), props: 'stuTutorNo', width: 90 },
                { label: this.$t('paperBlindTrial.stuTutorName'), props: 'stuTutorName', width: 80 },
                { label: this.$t('achievementApply.thesisTitle'), props: 'thesisTitle', width: 130 },
                // { label: this.$t('paperBlindTrial.batchName'), props: 'batchNo', width: 80 },
                { label: this.$t('paperBlindTrial.sendCount'), props: 'evaCount', width: 80 },
                { label: this.$t('paperBlindTrial.applicantTime'), props: 'createTime', width: 155 },
                // { label: this.$t('paperBlindTrial.needPassNum'), props: 'needPassCount', width: 90 },
                // { label: this.$t('paperBlindTrial.reviewCount'), props: 'reviewCount', width: 150 },
            ],
            options: {
              majorCode: [], // 专业
              academyCode: [], // 学院
              eduLevel: [], // 培养层次
              eduMode: [], // 培养类别
              degreeType: [], // 学位类型
              studyForm: [], // 学习形式
              passCount: [], // 送审次数
              manageDeptIds:[
                { label: this.$t('paperBlindTrial.general'), value: '2', type: '' },
                { label: this.$t('paperBlindTrial.onJob'), value: '4', type: '' }
              ],//管理部门
              resultType: [
                { label: this.$t('message.pass'), value: 'PASS', type: 'success' },
                { label: this.$t('message.noPass'), value: 'UNPASS', type: 'danger' },
                { label: this.$t('paperBlindTrial.toBeEntered'), value: 'INCOMPLETE'},
              ] // 评审结果
            },
            dialogFlag: false,
            enterFlag:false,
            typeInfo: '',
            titles: this.$t('paperBlindTrial.inputLabel'),
            selectionDatas: []
        };
    },
    computed: {

    },
    created() {
      // 获取当前用户auths权限
      if (localStorage.getItem("sessiondata")) {
        if (JSON.parse(localStorage.getItem("sessiondata")).auths) {
            this.auths = JSON.parse(localStorage.getItem("sessiondata")).auths;
        }
      }
    },
    watch: {
        auths: {
            handler(newVal) {
                if (newVal && Array.isArray(newVal) && newVal.length > 0) {
                    newVal.some(item => {
                        // 新增
                        if (item.authCode === 'paperReviewResult-clearEnterResult') {
                            this.authsBtnState.clearEnterResultState = true;
                        }
                    });
                }
            }
        }
    },
    mounted() {
      let param = {
        X_YX: 'academyCode', // 学院
        X_PYCC: 'eduLevel', // 培养层次
        X_PYLB: 'eduMode', // 培养类别
        X_XWLX: 'degreeType', // 学位类型
        K_XXXS: 'studyForm', // 学习形式
      };
      this.initOptions(param);

      for (let i = 1; i <= 50; i++) {
        let obj = { label: i, value: i, id: i };
        this.options.passCount.push(obj);
      }
    },
    methods: {
        //可用TeacherSelect通用组件替换
        selectTeacher(query) {
            if (!query) return
            const data = {
                condition: query,
                pageNum_: 1,
                pageSize_: 10
            }
            this.loading = true
            findTeacherInfoList(data)
                .then(res => {
                    this.loading = false
                    if (res.code == 200) {
                        this.teachers = this.transData(res.data.list, 'name', 'code')
                    } else throw res.code
                })
                .catch(error => {
                    this.loading = false
                    console.error("查询导师信息失败")
                })
        },

        transData(list, name, code) {
            return list.map((item, index, array) => {
                return {
                    label: item[name] + '(' + item[code] + ')',
                    value: item[code],
                }
            })
        },

        exportData() { // 导出
          let jsons = this.$refs.tables.selectionDatas;
          let param = {};
          let fileName = '';
          if (jsons && jsons.length > 0) { // 优先按勾选内容导出
            param.ids = jsons.map(v => v.applyId);
            param.type = 1;
          } else { // 存在搜索条件时则按搜索条件导出
            // fileName =
            //param.request = this.queryForm;
            if(this.queryForm.stuNoOrName ){
                param.request = {stuNoOrName:this.queryForm.stuNoOrName.trim()}
            }else{
                param.request = _.cloneDeep(this.queryForm);
                param.request.stuNoOrName = '';
            }
            param.type = 0;
          }
          resultTableExportTable(param);
        },
        showDialog(val, row) {
          this.titles = val == 'input' ? this.$t('paperBlindTrial.inputLabel') : this.$t('message.Look');
          this.dialogFlag = true;
          this.enterFlag = val === 'input';
          this.typeInfo = val;
          this.rows = row;
        },
        onSubmit() { // 筛选
          this.$refs.tables.pageNum = 1;
          let param = {};
          if(this.queryForm.stuNoOrName ){
            param = {stuNoOrName:this.queryForm.stuNoOrName.trim()}
          }else{
            param = _.cloneDeep(this.queryForm);
            param.stuNoOrName = '';
          }
          this.$refs.tables.search(param);
        },
        reset() {  // 重置
          for (const key in this.queryForm) {
            if (key !== 'yearTerm') {
              this.queryForm[key] = '';
            }
          }
          this.queryForm.yearTerm = this.yearTerms;
          this.onSubmit();
        },
        search() { // 搜索
          this.queryForm.stuNoOrName = this.queryForm.stuNoOrName.trim();
          this.onSubmit();
        },
        loadDone() { // 页面加载时保存学期学年
          this.yearTerms = this.queryForm.yearTerm;
          this.onSubmit();
        },
        // 录入成绩确定
        sure() {
          this.$refs.reviewDetails.save();
        },
        // 多选方法
        handleSelectionChange (val) {
          this.selectionDatas = val;
        },
        backFunc () {
          this.dialogFlag = false;
          this.onSubmit();
        },
        // 批量下载
        // batchDownload () {
        //   // if (this.selectionDatas.length === 0) {
        //   //   this.$message.error(this.$t('paperBlindTrial.downLoadTips'));
        //   //   return;
        //   // }
        //   let param = _.cloneDeep(this.queryForm);
        //   param.applyIds = this.selectionDatas.map(v=>v.applyId);
        //   adminAuditDownloadZip(param);
        // }

        //清除录入结果
        clearEnterResult(){
          if (this.selectionDatas.length === 0) {
            this.$message.error(this.$t('paperBlindTrial.clearTips'));
            return;
          }
          if (this.selectionDatas.length > 1) {
            this.$message.error(this.$t('paperBlindTrial.clearTips2'));
            return;
          }
          let param = this.selectionDatas.map(v => v.applyId)
          clearEnterResult(param).then(res=>{
            this.onSubmit();
          });
        }
    }
};
</script>

<style scoped lang="scss">
.con {
    &_searchRight {
        margin-left: 10px;
    }
}
.condition-title {
  color: #2b3b4e;
  font-size: 18px;
  line-height: 24px;
  font-weight: bold;
}
.tip {
  color: red;
  font-size: 14px;
  // line-height: 24px;
  font-weight: bold;
  float: left;
}
</style>

